package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.edu.mvcframework.annotations.LagouAutowired;
import com.lagou.edu.mvcframework.annotations.LagouController;
import com.lagou.edu.mvcframework.annotations.LagouRequestMapping;
import com.lagou.edu.mvcframework.annotations.Security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@LagouController
@LagouRequestMapping("/demo")
@Security(value = {"userName1", "userName2"})
public class DemoController {


    @LagouAutowired
    private IDemoService demoService;


    /**
     * URL: /demo/query?name=lisi
     *
     * @param request
     * @param response
     * @param name
     * @return
     */
    @LagouRequestMapping("/query")
    @Security(value = {"userName3", "userName4"})
    public String query(HttpServletRequest request, HttpServletResponse response, String name) {
        return demoService.get(name);
    }

    /**
     * 测试场景：
     * 1.类未添加 @Security 注释，方法未添加 @Security 注释
     * 1.1) http://localhost:8080/wmx/method1?name=wmx   应 可访问
     * 1.2) http://localhost:8080/wmx/method1?name=wmx&userLoginName=userName3   应 可访问
     * <p>
     * 2.类未添加 @Security 注释，方法添加 @Security 注释
     * 2.1) http://localhost:8080/wmx/query?name=wmx&userLoginName=userName3   应 可访问
     * 2.2) http://localhost:8080/wmx/query?name=wmx&userLoginName=userName    应 不可访问
     * 2.3) http://localhost:8080/wmx/query?name=wmx    应 不可访问
     * <p>
     * 3.类添加 @Security 注释，方法未添加 @Security 注释
     * 3.1) http://localhost:8080/demo/method1?name=wmx&userLoginName=userName1   应 可访问
     * 3.2) http://localhost:8080/demo/method1?name=wmx&userLoginName=userName3   应 不可访问
     * 3.3) http://localhost:8080/demo/method1?name=wmx     应 不可访问
     * <p>
     * 4.类添加 @Security 注释，方法添加 @Security 注释
     * 4.1) http://localhost:8080/demo/query?name=wmx&userLoginName=userName1   应 不可访问
     * 4.2) http://localhost:8080/demo/query?name=wmx&userLoginName=userName3   应 可访问
     * 4.3) http://localhost:8080/demo/query?name=wmx 应不可访问
     *
     * @param name
     * @return
     */
    @LagouRequestMapping("/method1")
    public String method1(HttpServletRequest request, HttpServletResponse response, String name) {
        return demoService.get(name);
    }
}
